package com.xhhospital.servlet;

import com.xhhospital.dao.BrxxDao;
import com.xhhospital.entity.Brxx;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "ShowBrxxServlet",urlPatterns = "/showBrxx")
public class ShowBrxxServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        String id1=request.getParameter("blbh");
//显示所有的数据库记录
        List<Brxx> list= BrxxDao.getBrxxById(id1);
        if(list!=null){
            request.setAttribute("chaxunBrxx",list);
            request.getRequestDispatcher("/chaxun.jsp").forward(request,response);
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        List<Brxx> list=new ArrayList<Brxx>();//从Dao数据，并船只传值到前端
        list= BrxxDao.showAllBrxx();
        if(list!=null){
            request.setAttribute("BrxxList",list);//使用request请求绑定键值对，方便JSP获取
            request.getRequestDispatcher("/chaxun2.jsp").forward(request,response);//请求转发到一个页面
        }
    }
}
